#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "gps.h"
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>

int gps_connect()
{
    struct gps_data_t gps_data;

    int ret = gps_open(GPSD_SHARED_MEMORY, "2947", &gps_data);

    (void) gps_stream(&gps_data, WATCH_ENABLE | WATCH_JSON, NULL);

    while (1){
	    usleep(100000);
	    /* Put this in a loop with a call to a high resolution sleep () in it. */
	    if (gps_waiting (&gps_data, 500)) {
		errno = 0;
		if (gps_read (&gps_data) == -1) {
		    fprintf(stderr, "GPS Error.\n");
		} else {
		    /* Display data from the GPS receiver. */
		    //if (gps_data.set & ...
		}
	    }

    }
    /* When you are done... */
    (void) gps_stream(&gps_data, WATCH_DISABLE, NULL);
    (void) gps_close (&gps_data);

    return 0;
}


int gps_fetch(gps_data_t* newData)
{
	return 0;
}
